/*
 * @Author: Your name
 * @Date:   2020-06-25 09:34:57
 * @Last Modified by:   Your name
 * @Last Modified time: 2020-06-27 09:49:01
 */
import axios from 'axios'
export function request(config){
    //创建axios的实例
    const instance = axios.create({
        baseURL: 'http://123.207.32.32:8000',
        timeout: 7000
    });

    //axios请求拦截器
    instance.interceptors.request.use(config => {
        return config; //拦截以后必须要返回拦截的配置，否则无法获取到网络请求
    },error => {
        console.log(error);
    });

    //axios响应拦截器
    instance.interceptors.response.use(res => {
        return res.data;
    },error => {
        console.log(error);
    })
    //返回真正的网络请求
    return instance(config);
}

//请求mockjs生成的数据
export function requestMock(config){
    //创建第二个实例专门用来请求mockjs数据
    const instance = axios.create({
        timeout:5000
    });
    instance.interceptors.request.use(config => {
        return config;
    },error => {
        console.log(error);
    });

    instance.interceptors.response.use(res => {
        return res.data;
    },error => {
        console.log(error);
    });
    return instance(config);
}